package com.example.mydemo.threadPool;

import java.util.concurrent.*;

/**
 * 无界队列
 */
public class LinkedBlockingQueueDemo {
    /**
     * 没有限制容量大小的队列
     *   服务器能很快的处理完每个任务，不至于存在有大量的阻塞任务
     */
    final static BlockingQueue blockingQueue = new LinkedBlockingQueue();

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 5, TimeUnit.SECONDS,
                blockingQueue, Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 10; i++) {
            executor.execute(()->{
                System.out.println(Thread.currentThread().getName());
            });
        }

    }
}
